package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Window;
import android.widget.TextView;

import com.woyowodaows.R;


/**
 * @author haiwei
 *         网络加载提示框
 *         2017/2/22
 */

public class ProgressBarDialog {

    private Context context;
    public Dialog dialog;
    private TextView tv_content;

    public ProgressBarDialog(Context context, String content) {
        this.context = context;
        initDialog(content);
    }

    private void initDialog(String content) {
        dialog = new Dialog(context, R.style.dialog);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_progress_bar);
        tv_content = (TextView) window.findViewById(R.id.tv_content);
        if (!TextUtils.isEmpty(content)) {
            tv_content.setText(content);
        }
    }

    /**
     * 显示dialog
     */
    public void showDialog() {
        if (dialog != null)
            dialog.show();
    }

    /**
     * 关闭dialog
     */
    public void dismissDialog() {
        if (dialog != null)
            dialog.dismiss();
    }

    /**
     * 设置进度条文本加载内容
     *
     * @param contentText
     */
    public void setContentText(String contentText) {
        if (!TextUtils.isEmpty(contentText)) {
            tv_content.setText(contentText);
        }
    }
}
